//package com.cskaoyan.gateway.controller.shopping;
//
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.cskaoyan.gateway.form.shopping.AddressForm;
//import com.mall.commons.result.ResponseData;
//import com.mall.commons.result.ResponseUtil;
//import com.mall.shopping.ICartService;
//import com.mall.shopping.IProductService;
//import com.mall.shopping.constants.ShoppingRetCode;
//import com.mall.shopping.dto.*;
//
//import com.mall.user.intercepter.TokenIntercepter;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.config.annotation.Reference;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//
//@Slf4j
//@RestController
//@RequestMapping("shopping")
//public class GoodsController {
//
//    @Reference(timeout = 3000, retries = 2, check = false)
//    IProductService productService;
//
//
//    @Reference(timeout = 3000, retries = 2, check = false)
//    ICartService cartService;
//
//
//    @GetMapping("goods")
//    public ResponseData getAllProduct(AllProductRequest request, HttpServletRequest servletRequest) {
//
////        String userInfo = (String) servletRequest.getAttribute(TokenIntercepter.USER_INFO_KEY);
////        JSONObject object = JSON.parseObject(userInfo);
////        Long uid = Long.parseLong(object.get("uid").toString());
//
//        AllProductResponse response = productService.getAllProduct(request);
//
//        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
//            return new ResponseUtil().setData(response.getMsg());
//        }
//        return new ResponseUtil().setErrorMsg(response.getMsg());
//    }
//
//    @GetMapping("recommend")
//    public ResponseData getRecommendGoods(HttpServletRequest servletRequest) {
//
//        RecommendResponse response = productService.getRecommendGoods();
//
//        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
//            return new ResponseUtil().setData(response.getMsg());
//        }
//        return new ResponseUtil().setErrorMsg(response.getMsg());
//    }
//
//    @GetMapping("carts")
//    public ResponseData getCartList(HttpServletRequest servletRequest) {
//        Long userIdFromServlet = Utils.getUserIdFromServlet(servletRequest);
//
//        CartListByIdRequest cartListByIdRequest = new CartListByIdRequest();
//        cartListByIdRequest.setUserId(userIdFromServlet);
//
//        CartListByIdResponse response = cartService.getCartListById(cartListByIdRequest);
//
//
//        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
//            return new ResponseUtil().setData(response.getMsg());
//        }
//        return new ResponseUtil().setErrorMsg(response.getMsg());
//    }
//
//    @PostMapping("carts")
//    public ResponseData addToCartList(@RequestBody AddCartRequest addCartRequest) {
//
//
//        AddCartResponse response = cartService.addToCart(addCartRequest);
//
//
//        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
//            return new ResponseUtil().setData(response.getMsg());
//        }
//        return new ResponseUtil().setErrorMsg(response.getMsg());
//    }
//
//
//}
//
//class Utils {
//
//    public static Long getUserIdFromServlet(HttpServletRequest servletRequest) {
//        String userInfo = (String) servletRequest.getAttribute(TokenIntercepter.USER_INFO_KEY);
//        JSONObject object = JSON.parseObject(userInfo);
//        Long uid = Long.parseLong(object.get("uid").toString());
//        return uid;
//    }
//
//}
